package com.ruoyi.teacher.special.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.teacher.special.domain.School;
import com.ruoyi.teacher.special.query.SchoolQuery;
import com.ruoyi.teacher.special.service.ISchoolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 心理特色学校Controller
 *
 * @author duanxinli
 * @date 2023-11-03
 */
@RestController
@RequestMapping("/school/special")
public class SchoolController extends BaseController {
    @Autowired
    private ISchoolService schoolService;

    /**
     * 查询心理特色学校列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(SchoolQuery schoolQuery) {
        startPage();
        List<School> list = schoolService.selectSchoolList(schoolQuery);
        return getDataTable(list);
    }

    /**
     * 导出心理特色学校列表
     */
    @PreAuthorize("@ss.hasPermi('school:special:export')")
    @Log(title = "心理特色学校", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SchoolQuery schoolQuery) {
        List<School> list = schoolService.selectSchoolList(schoolQuery);
        ExcelUtil<School> util = new ExcelUtil<School>(School.class);
        util.exportExcel(response, list, "心理特色学校数据");
    }

    /**
     * 获取心理特色学校详细信息
     */
    @Anonymous
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(schoolService.selectSchoolById(id));
    }

    /**
     * 新增心理特色学校
     */
    @PreAuthorize("@ss.hasPermi('school:special:add')")
    @Log(title = "心理特色学校", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody School school) {
        return toAjax(schoolService.insertSchool(school));
    }

    /**
     * 修改心理特色学校
     */
    @PreAuthorize("@ss.hasPermi('school:special:edit')")
    @Log(title = "心理特色学校", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody School school) {
        return toAjax(schoolService.updateSchool(school));
    }

    /**
     * 删除心理特色学校
     */
    @PreAuthorize("@ss.hasPermi('school:special:remove')")
    @Log(title = "心理特色学校", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(schoolService.deleteSchoolByIds(ids));
    }
}
